from Bases import ChildGroup
from basepage import BasePage
from .. import widgets
from groupcontrol import GroupSelect

class Palettes(BasePage):
    page_name = 'Palettes'
    def __init__(self, **kwargs):
        super(Palettes, self).__init__(**kwargs)
        self.current_group = None
        self.build_topwidget('Label', name='Palettes')
        self.group_select = self.topwidget.add_widget(GroupSelect, parent=self)
        self.group_select.bind(selection_changed=self.on_group_selection_changed)
        self.testmulti = self.topwidget.add_widget(widgets.MultiButton, name='testmultistuff', bounds=[.5, .5, .4, .4], rows=4, columns=6)
        self.testmulti.bind(button_pressed=self.on_testmulti_buttonpress)
        self.topwidget.refresh_interface()
        
    def on_group_selection_changed(self, **kwargs):
        print 'selection_changed: ', kwargs
        #self.selected_controls.set_group(kwargs.get('group'))
        self.current_group = kwargs.get('group')
        
    def on_testmulti_buttonpress(self, **kwargs):
        index = kwargs.get('index')
        if self.current_group is not None:
            p = self.MainController.EffectsSystem.CategoryPalettes[3][index+1]
            p.set_groups(group=self.current_group)
            p.active = True
        
class PaletteButtons(widgets.Label):
    def __init__(self, **kwargs):
        self.parent = kwargs.get('parent')
        super(PaletteButtons, self).__init__(**kwargs)
        
